Write native configuration files as UTF-8 - #36972
Closed
junhyeong9812 wants to merge 1 commit into
Closed
junhyeong9812 wants to merge 1 commit into
junhyeong9812 wants to merge 1 commit into
Conversation
FileNativeConfigurationWriter wrote native-image configuration files using a plain FileWriter, which encodes with the JVM platform default charset. On a non-UTF-8 platform (for example a Windows JVM, where the default charset is not UTF-8 prior to JDK 18) non-ASCII characters in resource patterns or bundle names were written with the wrong encoding, while GraalVM expects the configuration files to be UTF-8. Specify StandardCharsets.UTF_8 explicitly so the files are always written as UTF-8, consistent with the UTF-8 usage already present in the aot.generate package. Signed-off-by: junhyeong9812 <pickjog@gmail.com>
sbrannen
added a commit
that referenced
this pull request
Jun 27, 2026
Member
|
Good catch! 👍 This has been merged into Thanks |
Contributor
Author
|
Thanks for the quick review and merge, @sbrannen. Glad the single root-cause fix did the job. I really appreciate your time and feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
A small consistency/hardening change: make
FileNativeConfigurationWriteralways write the GraalVM native-image configuration files (reachability-metadata.json, etc.) as UTF-8.This is a minor edge-case fix rather than a critical bug; the trigger is narrow (see below), so please feel free to decline if you consider it not worth the change.
Problem
writeTouses a plainFileWriter:FileWriterwithout an explicit charset encodes using the JVM platform default charset, which is not UTF-8 on every supported configuration (for example a Windows JVM, where the default is a code-page charset such as windows-1252 prior to JDK 18 / JEP 400).BasicJsonWriterpasses non-ASCII characters through unescaped, so the on-disk encoding is decided entirely by the writer's charset. GraalVM expects these files to be UTF-8, so on a non-UTF-8 platform non-ASCII characters in resource patterns or bundle names could be written with the wrong encoding.The conditions are narrow (a non-UTF-8 default charset combined with non-ASCII content), so this is more of a hardening/consistency improvement than a frequently hit bug.
Fix
Specify
StandardCharsets.UTF_8explicitly:This is consistent with the explicit UTF-8 usage already present in the
aot.generatepackage.A test writes a resource pattern containing a non-ASCII character and asserts that the raw file bytes contain its UTF-8 byte sequence. Note that on a JVM whose default charset is already UTF-8 (such as the CI environment) the test passes both before and after the change; it serves as a guard on non-UTF-8 platforms and documents the intended encoding. The correctness of the fix itself rests on the
FileWriter(File, Charset)contract rather than on reproducing a non-UTF-8 default in CI.